﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWordAddIn.Tool
{
    class CheckPassword
    {
      
        /// <summary>
        /// 计算密码强度
        /// </summary>
        /// <param name="password">密码字符串</param>
        /// <returns></returns>
        public static int PasswordStrength(string password)
        {
            //空字符串强度值为0
            if (password == "") return 0;
            //字符统计
            int iNum = 0, iLtt = 0, iSym = 0;
            foreach (char c in password)
            {
                if (c >= '0' && c <= '9') iNum++;
                else if (c >= 'a' && c <= 'z') iLtt++;
                else if (c >= 'A' && c <= 'Z') iLtt++;
                else iSym++;
            }
            if (iLtt == 0 && iSym == 0) return 0; //纯数字密码
            if (iNum == 0 && iLtt == 0) return 0; //纯符号密码
            if (iNum == 0 && iSym == 0) return 0; //纯字母密码
            if (password.Length <= 6) return 0; //长度不大于6的密码
            if (iLtt == 0) return 1; //数字和符号构成的密码
            if (iSym == 0) return 1; //数字和字母构成的密码
            if (iNum == 0) return 1; //字母和符号构成的密码
            if (password.Length <= 10) return 1; //长度不大于10的密码
            return 2; //由数字、字母、符号构成的密码
        }
    }
}
